<?php 

//Include the Config and Database connect file
require_once ("system/config/config.php");
require_once ("system/db/dbconnect.class.php");

//Start The Connection
$db = new Connection();

$dropcart = "DROP TABLE IF EXISTS `cart`";
mysql_query($dropcart) or die (mysql_error());


$dropcat = "DROP TABLE IF EXISTS `categories`";
mysql_query($dropcat) or die (mysql_error());

$dropcatg = "DROP TABLE IF EXISTS `categories_group`";
mysql_query($dropcatg) or die (mysql_error());

$dropex = "DROP TABLE IF EXISTS `extraFunctions`";
mysql_query($dropex) or die (mysql_error());

$droplogin = "DROP TABLE IF EXISTS `login_in_record`";
mysql_query($droplogin) or die (mysql_error());

$droporders = "DROP TABLE IF EXISTS `orders`";
mysql_query($droporders) or die (mysql_error());

$droppost = "DROP TABLE IF EXISTS `posItems`";
mysql_query($droppost) or die (mysql_error());

$droppromo = "DROP TABLE IF EXISTS `promotionalItems`";
mysql_query($droppromo) or die (mysql_error());

$droppromotion = "DROP TABLE IF EXISTS `promotions`";
mysql_query($droppromotion) or die (mysql_error());

$droprep = "DROP TABLE IF EXISTS `reports`";
mysql_query($droprep) or die (mysql_error());

$dropsec = "DROP TABLE IF EXISTS `sectors";
mysql_query($dropsec) or die (mysql_error());

$dropsub = "DROP TABLE IF EXISTS `subcategories`";
mysql_query($dropsub) or die (mysql_error());

$dropuserlog = "DROP TABLE IF EXISTS `user_login`";
mysql_query($dropuserlog) or die (mysql_error());

$dropuserprof = "DROP TABLE IF EXISTS `user_profile`";
mysql_query($dropuserprof) or die (mysql_error());

$dropusergrp = "DROP TABLE IF EXISTS `users_group`";
mysql_query($dropusergrp) or die (mysql_error());

$createcart = "CREATE TABLE `cart` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`ct_session_id` varchar(255) NOT NULL,
  
		`order` LONGTEXT NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createcart) or die (mysql_error());


$createcat = "CREATE TABLE `categories` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`sectorId` int(11) NOT NULL,
  
		`nameOfCategory` varchar(255) NOT NULL,
		
		`parent` varchar(255) NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createcat) or die (mysql_error());

$createcat_group =	"CREATE TABLE `categories_group` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`nameOfGroup` varchar(100) DEFAULT NULL,
  
		`sector` int(11) DEFAULT NULL,
  
		`category_id` int(11) DEFAULT NULL,
  
		`promo_id` int(11) DEFAULT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createcat_group) or die (mysql_error());
	
$createextra = "CREATE TABLE `extraFunctions` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`nameOfFunction` varchar(100) NOT NULL,
 
		`functionDisplayName` varchar(100) NOT NULL,
  
		`description` varchar(255) NOT NULL,
  
		`question` varchar(255) NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createextra) or die (mysql_error());
	
$createlogin = "CREATE TABLE `login_in_record` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`username` varchar(50) DEFAULT NULL,
 
		`session_id` varchar(100) DEFAULT NULL,
  
		`ordered` int(11) NOT NULL,
  
		`timestamp` varchar(30) DEFAULT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createlogin) or die (mysql_error());
	
$createorder = "CREATE TABLE `orders` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`order_id` int(11) NOT NULL,
  
		`name_of_promo` varchar(255) NOT NULL,
  
		`order` longtext NOT NULL,
  
		`price` varchar(10) NOT NULL,
  
		`lob` varchar(50) NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createorder) or die (mysql_error());
	
$createpostit = "CREATE TABLE `posItems` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`itemName` varchar(100) NOT NULL,
  
		`dimensions` varchar(20) NOT NULL,
  
		`description` text NOT NULL,
  
		`notes` text NOT NULL,
  
		`defaultPrice` float NOT NULL,
  
		`type` varchar(50) NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createpostit) or die (mysql_error());
	
$createpromotionit = "CREATE TABLE `promotionalItems` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`itemName` varchar(30) NOT NULL,
 
		`ItemCost` varchar(6) NOT NULL,
 
		`freePOS` tinyint(1) NOT NULL,
  
		`extraInfo` varchar(255) NOT NULL,
  
		`dimensions` varchar(10) NOT NULL,
  
		`promotionId` int(11) NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createpromotionit) or die (mysql_error());

$createpromotion = "CREATE TABLE `promotions` (
 
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`sector` varchar(3) NOT NULL,
  
		`category` varchar(3) NOT NULL,
  
		`nameOfPromotion` varchar(200) NOT NULL,
  
		`promotionalImages` varchar(255) NOT NULL,
  
		`promotionalItems` longtext NOT NULL,
  
		`deliveryCost` varchar(6) NOT NULL,
  
		`extras` longtext NOT NULL,
  
		`subcategory` int(11) DEFAULT NULL,
  
		`startdate` varchar(10) DEFAULT NULL,
  
		`enddate` varchar(10) DEFAULT NULL,

		`targetdate` varchar(10) DEFAULT NULL,
		
		`frontDisplay` int(2) DEFAULT NULL,
		
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createpromotion) or die (mysql_error());
	
$createreports = "CREATE TABLE `reports` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`order_number` int(11) NOT NULL,
  
		`user_name` varchar(50) NOT NULL,
  
		`address` varchar(255) NOT NULL,
  
		`lob` varchar(50) NOT NULL,
  
		`date` date NOT NULL,
  
		`ops_manager` varchar(255) NOT NULL,
  
		`total_price` float DEFAULT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createreports) or die (mysql_error());
	
$createsectors = "CREATE TABLE `sectors` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`nameOfSector` varchar(100) NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createsectors) or die (mysql_error());

$createsubs = "CREATE TABLE `subcategories` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`sectionId` int(11) NOT NULL,
  
		`title` varchar(255) NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createsubs) or die (mysql_error());
	
$createuser_login = "CREATE TABLE `user_login` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`username` varchar(20) NOT NULL,
  
		`password` varchar(50) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
  
		`accessLevel` int(11) NOT NULL,
  
		`firstname` varchar(30) NOT NULL,
  
		`lastname` varchar(50) NOT NULL,
  
		`lastlogged` varchar(30) NOT NULL,
  
		`loggedInAmount` int(11) NOT NULL,
  
		`dateAdded` datetime NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createuser_login) or die (mysql_error());
	
$createuser_profile = "CREATE TABLE `user_profile` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`loginId` int(11) NOT NULL,
  
		`address1` varchar(255) NOT NULL,
  
		`address2` varchar(255) NOT NULL,
  
		`city` varchar(100) NOT NULL,
  
		`postcode` varchar(10) NOT NULL,
  
		`email` varchar(50) NOT NULL,
  
		`lob` varchar(40) NOT NULL,
  
		`opsManager` varchar(50) NOT NULL,
  
		`opsEmail` varchar(50) NOT NULL,
  
		`templateChosen` varchar(10) NOT NULL,
  
		`logo` varchar(20) NOT NULL,
 
		`coffee` varchar(30) NOT NULL,
  
		`ordered` int(11) NOT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createuser_profile) or die (mysql_error());
	
$createuser_group = "CREATE TABLE `users_group` (
  
		`id` int(11) NOT NULL AUTO_INCREMENT,
  
		`groupId` int(11) DEFAULT NULL,
  
		`userId` varchar(50) DEFAULT NULL,
  
		PRIMARY KEY (`id`)
)";
		
		mysql_query($createuser_group) or die (mysql_error());

$admindetails = "INSERT INTO user_profile VALUES (NULL, '1', 'Studio 14 Weekin Works 112-116 Park Hill Road', 'Harborne', 'Birmingham', 'B17 9HD', 'carl@caramba-marketing.co.uk', '', 'Chris Mann', 'chris@caramba-marketing.co.uk', '', '', '', '')";
mysql_query($admindetails) or die (mysql_error());

$adminlogin = "INSERT INTO user_login VALUES (NULL, 'admin', MD5('caramba'), '10', 'Carl', 'Wells', '0', '0', NOW())";
mysql_query($adminlogin) or die (mysql_error());

$extraFunc = "INSERT INTO `extraFunctions` VALUES 
		
('1','writeNumberOfItems','Write Number Of Items','Use this function to give the user the option to specify the number of items','Does the user need to specify the number of items?'),
('2','foodItems','Food Items','Display a dropdown list of Food Items','Does the user need to specify a particular Food Item i.e Sandwich, Roll or Baguette?'),
('3','writeDays','Write Days','Display a Dropdown List of Weekdays','Does the user need to specify a particular day?'),
('4','writeOwnWords','Write Own Words','Display a text box to allow the user to add their own copy','Does the user need to add their own words to a promotion?'),
('5','addOwnPrice','Add Own Price','Display a text box to allow a user to input their own price','Does the user need to display a price on the promotion?'),
('6','pricePoint','Price Point','Display a Dropdown list containing specific prices within a specified range','Does the user need to supply a specified price point?'),
('7','writeTimes','Write Times','Display a dropdown list with specific times.','Does the promotion need a range of times displayed?'),
('8','discountTable','Discount Table','Add a link to allow the user to download a file containing Promotional info','Does the promotion have a supporting file to download')";

mysql_query($extraFunc) or die (mysql_error());

$postItems = "INSERT INTO `posItems` VALUES 

('1','Banner Stand Graphic','','','','47','Banners'),
('2','Banner Stand','','','','55','Banners'),
('3','Shelf Barkers','','','Set of 3','3.25','POS'),
('4','Acetates','','','','1.5','POS'),
('5','A0','841x1189mm','','','19.5','Posters'),
('6','A1','594x841mm','','','9.5','Posters'),
('7','A2','420x594mm','','','5','Posters'),
('8','A3','297x420mm','','','2.75','Posters'),
('9','A4','210x297mm','','','1','Posters'),
('10','DL Table Talker Inserts','99x210mm','','Pack of 10','5','Table Talkers'),
('11','Acrylic Table Talker Holders','','','','2.82','Table Talkers')";

mysql_query($postItems) or die (mysql_error());

header("location:index.php");


?>